<template>
  <div class="log-container">
    <el-card class="box-card">
      <div class="search">
          <div class="item" style="margin-right:10px;">
              <span style="margin-right:5px;">用户Id</span>
              <el-input 
                  style="width: 300px"
                  v-model="query.userId"
                  clearable 
                  @clear="getLogList"></el-input>
          </div>
          <div class="item">
              <span style="margin-right:5px;">用户名</span>
              <el-input 
                  style="width: 300px"
                  v-model="query.userName"
                  clearable 
                  @clear="getLogList"></el-input>
          </div>
          <el-button type="primary" class="searchBtn btn" icon="el-icon-search" @click="getLogList">查询</el-button>
        </div>
        <div class="table">
          <el-table 
             width="100%"
            :data="tableData"
            stripe border>
            <el-table-column prop="id" label="Id" width="100" />
            <el-table-column prop="userId" label="用户Id" width="150" />
            <el-table-column prop="userName" label="用户名" width="150" />
            <el-table-column prop="realName" label="真实姓名" width="150" />
            <el-table-column prop="content" label="动态" />
            <el-table-column  label="创建时间" width="160px">
                <template slot-scope="scope">
                      {{scope.row.createTime | dateFormat}}
                </template>
              </el-table-column>
          </el-table>
          <!-- 分页区域 -->
          <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                class="pagination"
                :current-page="query.pageIndex"
                :page-sizes="[1, 2, 5, 10]"
                :page-size="query.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
          </el-pagination>
        </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data(){
    return {
      query: {
        userId: null,
        userName: null,
        pageIndex: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0
    }
  },
  created(){
    if(this.userLogId != null && this.userLogId!=''){
      this.query.userId = this.userLogId;
      this.$store.commit("initUserLogId","");
    }
    this.getLogList();
  },
  computed:{
    userLogId(){
      return this.$store.state.userLogId;
    }
  },
  methods:{
    getLogList(){
      this.getRequest("/api/admin/user/event/page/list",{
        userId: this.query.userId,
        userName: this.query.userName,
        pageIndex: this.query.pageIndex,
        pageSize: this.query.pageSize
      }).then(resp => {
        if(resp){
          this.tableData = resp.data;
          this.total = resp.total;
        }
      })
    },
     //监听pagesize改变的事件
    handleSizeChange(newSize) {
      
        //console.log(newSize);
        this.query.pageSize = newSize
        this.getLogList();
    },
    //监听页码值改变的事件
    handleCurrentChange(newPage) {
        //console.log(newPage);
        this.query.pageIndex = newPage
        this.getLogList();
    }
  }
}
</script>

<style lang="scss" scoped>
.log-container{
  font-family: "华文楷体";
  .box-card{
      border-radius: 10px;
      color:#1A1A1A;
      .search{
        margin-top: 10px;
        display: flex;
        align-items: center;
        color:#1A1A1A;
        font-family: "黑体";
        .searchInput{
          margin-left: 10px;
          border:1px solid #1980FF;
          border-radius: 4px;
        }
        .btn{
          margin: 0 0 0 20px;
          font-family: "华文楷体";
        }
    }
    .table{
         margin-top: 20px;
         width: 100%;
         //内容居中
         /deep/.el-table th > .cell {
              text-align: center;
          }
          
          /deep/.el-table .cell {
              text-align: center;
          } 
          .btns{
            display: flex;
            justify-content: space-around;
          }
          .btn{
            border: none;
            font-size: 12px;
            margin:0 10px;
            padding: 0;
            cursor: pointer;
            &:nth-child(1){
              color:#1980FF;
            }
             &:nth-child(2){
              color:#F56C6C;
            }
          }
      }
      .pagination{
        margin: 20px 0 0 0;
        display: flex;
        justify-content: flex-end;
      }
  }
}
</style>